<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="/layout/template.xhtml">

<ui:define name="body">

    <h:form id="questionario" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{questionarioHome.managed ? 'Editar' : 'Cadastro de'} Questionário</f:facet>

			<s:div styleClass="tableControl" rendered="#{empty from}">
        		<s:link view="/resources/QuestionarioList.xhtml"
		                    id="list"
		           propagation="none">
		            <h:graphicImage url="/img/list.png"/>
		            #{' '}
		            <h:outputLabel value="Listagem"/>
		        </s:link>
		    </s:div>


            <s:decorate id="nomeField" template="/layout/edit.xhtml">
                <ui:define name="label">Nome</ui:define>
                <h:inputText id="nome" value="#{questionarioHome.instance.nome}" required="true"/>
            </s:decorate>
            
            
            <s:decorate id="descricaoField" template="/layout/edit.xhtml">
                <ui:define name="label">Descrição</ui:define>
                <h:inputText id="nome" value="#{questionarioHome.instance.descricao}" required="true"/>
            </s:decorate>
            
            
            <s:decorate id="nivelField" template="/layout/edit.xhtml">
                <ui:define name="label">Nível</ui:define>
                <h:panelGrid columns="1">
                	<rich:inputNumberSpinner id="nivel" value="#{questionarioHome.instance.nivel}" maxValue="100" minValue="1" required="true"/>
                </h:panelGrid>
            </s:decorate>


            <div style="clear:both">
                <span class="required">*</span>
                campo obrigatório
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Salvar"
                         action="#{questionarioHome.persist}"
                       disabled="#{!questionarioHome.wired}"
                       rendered="#{!questionarioHome.managed}"/>

            <h:commandButton id="update"
                          value="Salvar"
                         action="#{questionarioHome.update}"
                       rendered="#{questionarioHome.managed}"/>

            <h:commandButton id="delete"
                          value="Deletar"
                         action="#{questionarioHome.remove}"
                      immediate="true"
                       rendered="#{questionarioHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancelar"
             propagation="end"
                    view="/resources/Questionario.xhtml"
                rendered="#{questionarioHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancelar"
             propagation="end"
                    view="/resources/#{empty questionarioFrom ? 'QuestionarioList' : questionarioFrom}.xhtml"
                rendered="#{!questionarioHome.managed}"/>

			<s:button view="/resources/Quiz.xhtml"
	        			id="quiz"
	        		 value="Quiz!"
                  rendered="#{not empty usuario.id}"
	           propagation="begin">
	           
	           <f:param name="questionarioId"
	           		   value="#{questionarioHome.instance.id}"/>
	           <f:param name="usuarioId"
	           		   value="#{usuario.id}"/>
	        </s:button>
        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Categoria">
    <div class="association" id="categoriaParent">

        <h:outputText value="Não existe Categoria associada a este Questionário."
                   rendered="#{questionarioHome.instance.categoria == null}"/>

        <rich:dataTable var="_categoria"
                   value="#{questionarioHome.instance.categoria}"
                rendered="#{questionarioHome.instance.categoria != null}"
              rowClasses="odd,even"
                      id="categoriaTable">
            <h:column>
                <f:facet name="header">Nome</f:facet>
                <h:outputText value="#{_categoria.nome}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Descrição</f:facet>
                <h:outputText value="#{_categoria.descricao}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Usuário</f:facet>
                <h:outputText value="#{_categoria.usuario.nome}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{questionarioHome.instance.categoria != null ? 'changeParentCategoria' : 'selectParentCategoria'}" value="#{questionarioHome.instance.categoria != null ? 'Trocar' : 'Selecionar'} Categoria"
                       view="/resources/CategoriaList.xhtml"
                   rendered="#{s:hasRole('Subgrupo') or permissao.meuQuestionario}">
                <f:param name="from" value="QuestionarioEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>

    <rich:tab label="Usuário">
    <div class="association" id="usuarioParent">

        <h:outputText value="Não existe usuário associado a este Questionário."
                   rendered="#{questionarioHome.instance.usuario == null}"/>

        <rich:dataTable var="_usuario"
                   value="#{questionarioHome.instance.usuario}"
                rendered="#{questionarioHome.instance.usuario != null}"
              rowClasses="odd,even"
                      id="usuarioTable">
            
            <h:column>
                <f:facet name="header">Nome</f:facet>
                <h:outputText value="#{_usuario.nome}"/>
            </h:column>
            <h:column>
                <f:facet name="header">E-mail</f:facet>
                <h:outputText value="#{_usuario.email}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Status</f:facet>
                <h:outputText value="#{_usuario.status}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Data de Cadastro</f:facet>
                <h:outputText value="#{_usuario.dataCadastro.time}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{questionarioHome.instance.usuario != null ? 'changeParentUsuario' : 'selectParentUsuario'}" value="#{questionarioHome.instance.usuario != null ? 'Trocar' : 'Selecionar'} usuário"
                       view="/resources/UsuarioList.xhtml"
                       rendered="#{s:hasRole('Subgrupo')}">
                <f:param name="from" value="QuestionarioEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>

    <rich:tab label="Questão">
        <h:form styleClass="association" id="questaoChildren">

            <h:outputText value="Não existe Questão cadastrada."
                       rendered="#{empty questionarioHome.questao}"/>

            <rich:dataTable value="#{questionarioHome.questao}"
                           var="_questao"
                      rendered="#{not empty questionarioHome.questao}"
                    rowClasses="odd,even"
                            id="questaoTable">
                <rich:column sortBy="#{_questao.questao}">
                    <f:facet name="header">Enunciado</f:facet>
                    <h:outputText value="#{_questao.questao}"/>
                </rich:column>
                <rich:column sortBy="#{_questao.acertos}">
                    <f:facet name="header">Acertos</f:facet>
                    <h:outputText value="#{_questao.acertos}"/>
                </rich:column>
                <rich:column sortBy="#{_questao.erros}">
                    <f:facet name="header">Erros</f:facet>
                    <h:outputText value="#{_questao.erros}"/>
                </rich:column>
                <rich:column sortBy="#{_questao.tipoQuestao}">
                    <f:facet name="header">Tipo da Questão</f:facet>
                    <h:outputText value="#{_questao.tipoQuestao}"/>
                </rich:column>
            </rich:dataTable>

        </h:form>

        <f:subview rendered="#{questionarioHome.managed}" id="questao">
        <div class="actionButtons">
            <s:button id="addquestao"
                   value="Cadastrar Questão"
                    view="/resources/QuestaoEdit.xhtml"
             propagation="none">
                 <f:param name="questionarioId"
                         value="#{questionarioHome.instance.id}"/>
                 <f:param name="questaoFrom" value="Questionario"/>
            </s:button>
        </div>
        </f:subview>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
